package org.nemanjaristic.utils;

import java.sql.DriverManager;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;

public class ConnectionUtils {

	private static Connection con;

	private static String URL = "jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=utf8";
	private static String USER = "root";
	private static String PW = "root";

	private static Connection createConnection() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			con = (Connection) DriverManager.getConnection(URL, USER, PW);
			con.setCharacterEncoding("UTF-8");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return con;
	}
	
	public static Connection getConnection(){
		if(con != null)
			return con;
		else
			return createConnection();	
	}
}
